/**
 * 登录用户状态管理
 */
import { defineStore } from 'pinia';
import { listMesCustomerInformations } from '@/api/mes/mesCustomerInformation';

export const useCustomerStore = defineStore('customer', {
  state: () => ({
    customerList: [],
  }),
  actions: {
    async fetchCustomerList() {
      listMesCustomerInformations().then((data) => {
        this.customerList = data.rows || []
        sessionStorage.setItem('customerList', JSON.stringify(data.rows))
      })
    },
    /**
     * 更新用户信息
     */
    setCustomerList(data) {
      this.customerList = data
    },
  },
  getters: {
    /** 需要缓存的路由组件 */
    getCustomerList() {
      return this.customerList;
    }
  },
});
